package neusoft.example.com.yuejian06.Activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import neusoft.example.com.yuejian06.Fragment.ActivityFragment;
import neusoft.example.com.yuejian06.Model.ActivityModel;
import neusoft.example.com.yuejian06.PublicActivity;
import neusoft.example.com.yuejian06.R;
import neusoft.example.com.yuejian06.RetrofitListener;

public class ActivityDetailActivity extends AppCompatActivity {
    private Intent intent;
    private ImageView activity_return;
    private ImageView activity_pic;
    private String user_id;
    private String activity_id;
    private TextView activity_title;
    private TextView activity_intro;
    private TextView activity_time;
    private TextView activity_sprice;
    private TextView activity_address;
    private TextView activity_notice;
    private Button activity_baoming;

    private RetrofitListener<neusoft.example.com.yuejian06.Bean.Activity> activitylistener;
    private RecyclerView recyclerView;
    private ActivityModel activityModel;
    private LinearLayoutManager layoutManager;

    private PublicActivity publicActivity;
    private SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_detail);

        ActionBar actionBar = getSupportActionBar();
        if(actionBar != null){
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        initView();

        sp = getSharedPreferences("user_id", MODE_PRIVATE);
        user_id = sp.getString("user_id", null);
        activity_id = getIntent().getStringExtra("activity_id");


        layoutManager = new LinearLayoutManager(ActivityDetailActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        activitylistener=new RetrofitListener<neusoft.example.com.yuejian06.Bean.Activity>() {
            PublicActivity publicActivity=new PublicActivity();
            @Override
            public void onResponse(neusoft.example.com.yuejian06.Bean.Activity l) {
                Picasso.with(ActivityDetailActivity.this)
                        .load(publicActivity.getIp()+"static/picture/"+l.getActivity_pic())
                        .into(activity_pic);

                activity_title.setText(l.getActivity_title());
                activity_address.setText(l.getActivity_address());
                activity_sprice.setText(l.getActivity_sprice());
                activity_notice.setText(l.getActivitynotice());
                activity_time.setText(l.getActivity_time());
                activity_intro.setText(l.getActivity_intro());
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(ActivityDetailActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        };

        activityModel = new ActivityModel();
        activityModel .getActivity(activity_id, activitylistener);


        activity_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intent=new Intent(ActivityDetailActivity.this, ActivityFragment.class);
                startActivity(intent);
            }
        });
    }

    private void initView(){
        activity_pic = (ImageView) findViewById(R.id.activity_pic);
        activity_return = (ImageView) findViewById(R.id.activity_return);
        activity_title = (TextView) findViewById(R.id.activity_title);
        activity_time = (TextView) findViewById(R.id.activity_time);
        activity_address = (TextView) findViewById(R.id.activity_address);
        activity_intro=(TextView)findViewById(R.id.activity_intro);
        activity_notice=(TextView)findViewById(R.id.activity_notice);
        activity_sprice=(TextView)findViewById(R.id.activity_sprice);
    }
}
